package com.taotao.rop.service;

import com.rop.annotation.HttpAction;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import com.taotao.rop.database.domain.WechatAccesstoken;
import com.taotao.rop.database.mapper.WechatAccesstokenMapper;
import com.taotao.rop.response.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@ServiceMethodBean(httpAction = HttpAction.POST, version = "1.0")
public class WechatAccesstokenService {
    @Autowired
    private WechatAccesstokenMapper mapper;

    @ServiceMethod(method = "accesstoken.count", needInSession = NeedInSessionType.NO)
    public Object getCount(WechatAccesstoken request) {
        Long count = mapper.getCount(request);

        BaseResponse<Long> response = new BaseResponse<Long>();
        response.setSuccess(true);
        response.setData(count);
        return response;
    }

    @ServiceMethod(method = "accesstoken.list", needInSession = NeedInSessionType.NO)
    public Object listAccesstoken(WechatAccesstoken request) {
        List<WechatAccesstoken> roleList = mapper.getList(request);

        BaseResponse<List<WechatAccesstoken>> response = new BaseResponse<List<WechatAccesstoken>>();
        response.setSuccess(true);
        response.setMsg("" + mapper.getCount(request));
        response.setData(roleList);
        return response;
    }
    @ServiceMethod(method = "accesstoken.insert", needInSession = NeedInSessionType.NO)
    public Object insertAccesstoken(WechatAccesstoken request) {
        Integer count = mapper.insertOne(request);

        BaseResponse<Integer> response = new BaseResponse<Integer>();
        response.setSuccess(true);
        response.setData(count);
        return response;
    }

    @ServiceMethod(method = "accesstoken.update", needInSession = NeedInSessionType.NO)
    public Object updateAccesstoken(WechatAccesstoken request) {
        Integer count = mapper.updateOne(request);

        BaseResponse<Integer> response = new BaseResponse<Integer>();
        response.setSuccess(true);
        response.setData(count);
        return response;
    }
}
